/*
 * Please have a look at the example_...js files! 
 * CustJsonRPCDataSource specifics are explained there.
 * Here you will only find standard SmartClient code. 
 * 
*/

taskRefreshTimerEvent = null;   // timer somethimes used in tasks

isc.DynamicForm.create({
    ID: "DynamicFormTop",
    autoDraw: false,
    
    padding: 15,
    fields: [
        {defaultValue: "CustJsonRPCDataSource - Examples", name: "HeaderItemTop", type: "header"},
    ]
});

isc.TreeGrid.create({
    ID: "TreeGridTasks",
    autoDraw: false,
    
    alternateRecordStyles: true,
    leaveScrollbarGap: false,
    nodeIcon: isc.Page.getSkinImgDir() + "FileBrowser/file.png",
    folderIcon: isc.Page.getSkinImgDir() + "FileBrowser/folder.png",
    showHeader: false,
    
    showOpenIcons: false,
    showDropIcons: false,
    closedIconSuffix:"",
    data: isc.Tree.create({
        modelType: "parent",
        rootValue: "1",
        nameProperty: "Name",
        idField: "Id",
        parentIdField: "Category",
        data: [
            {Id:"10", Category:"1", Name:"Welcome"},
            {Id:"101", Category:"10", Name:"Welcome", Url:"readme.js"},
            {Id:"20", Category:"1", Name:"ListGrid"},
            {Id:"201", Category:"20", Name:"Fetch", Url: isc.Page.getAppFilesDir() + "example_listgrid_fetch.js"},
            {Id:"202", Category:"20", Name:"Fetch with server error", Url: isc.Page.getAppFilesDir() + "example_listgrid_fetch_server_error.js"},
            {Id:"203", Category:"20", Name:"Fetch with application error", Url: isc.Page.getAppFilesDir() + "example_listgrid_fetch_application_error.js"},
            {Id:"30", Category:"1", Name:"DynamicForm"},
            {Id:"301", Category:"30", Name:"Fetch", Url: isc.Page.getAppFilesDir() + "example_dynamicForm_fetch.js"},
            {Id:"302", Category:"30", Name:"Add/Update", Url: isc.Page.getAppFilesDir() + "example_dynamicForm_add.js"},
            {Id:"304", Category:"30", Name:"Remove", Url: isc.Page.getAppFilesDir() + "example_dynamicForm_remove.js"},
            {Id:"305", Category:"30", Name:"Validation error", Url: isc.Page.getAppFilesDir() + "example_dynamicForm_validation_error.js"}
        ]
    })
});

TreeGridTasks.openLeaf = function (node) {
    this.Super("openLeaf", arguments);
    Timer.clear(taskRefreshTimerEvent);
    taskRefreshTimerEvent = null;
    ViewLoaderTasks.setViewURL(node.Url);
};

TreeGridTasks.openFolder(TreeGridTasks.data.findById("10"));
TreeGridTasks.selectRecord(TreeGridTasks.data.findById("101"));

isc.HTMLPane.create({
    ID: "HTMLPaneAbout",
    autoDraw: false,
    height: 180,
    contents: "<span class='headerItem'>CustJsonRPCData&nbsp;&nbsp;</span> is a Json-RPC data source for SmartClient currently under development. Use it if it helps you or participate and improve it!"
});



isc.SectionStack.create({
    ID:"SectionStackMain",
    autoDraw:false,
    showResizeBar: true,
    width: "220",
    
    visibilityMode: "multiple",
    sections:[
        {   ID:"SectionStackTasks",
            autoShow:true,
            title:"Examples",
            items:[ TreeGridTasks ]},
        {   ID:"SectionStackHelp",
            autoShow:false,
            title:"About",
            items:[ HTMLPaneAbout ]}
    ]
});

isc.ViewLoader.create({
    ID: "ViewLoaderTasks",
    autoDraw: false,
    viewURL: "readme.js",
    loadingMessage: "Loading welcome page..."
});

isc.HLayout.create({
    ID: "HLayoutMain",
    autoDraw: false,
    backgroundColor: "#C0C0C0",
    members: [
        SectionStackMain,
        ViewLoaderTasks
    ]
});

isc.VLayout.create({
    ID: "VLayoutMain",
    autoDraw: true,
    width: "100%",
    height: "100%",
    members: [
        DynamicFormTop,
        HLayoutMain
    ]
});
